<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
</head>
  <title>承继协议</title>
  <style type="text/css">
  	.layui-form-select dl{
		max-height: 150px; // 原值为300，调节高度建议为50的倍数
	}
	.layui-form-label{width: 130px;}
	.layui-form-item {
	    margin-bottom: 0px;
	    clear: both;
	    *zoom: 1;
	}
  </style>
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
       	<div class="layui-form-item">
          	<div class="layui-inline">
            	<label class="layui-form-label">单据ID</label>
            	<div class="layui-input-inline">
              		<input type="text" name="codes" placeholder="请输入单据编号" autocomplete="off" class="layui-input">
            	</div>
          	</div>
          	<div class="layui-inline">
            	<label class="layui-form-label">项目名称</label>
            	<div class="layui-input-inline">
              		<input type="text" name="proName" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
            	</div>
          	</div>
          	<div class="layui-inline">
             	<label class="layui-form-label">创建日期</label>
             	<div class="layui-input-inline">
               		<input type="text" class="layui-input" id="sent-laydate-start" name="startDate" readonly placeholder="开始日期">
             	</div>
             	<div class="layui-form-mid">
               	-
             	</div>
             	<div class="layui-input-inline">
               		<input type="text" class="layui-input" id="sent-laydate-end" name="endDate" readonly placeholder="结束日期">
             	</div>
       		</div>
       	</div>
       	<div class="layui-form-item">
          	<div class="layui-inline">
            	<label class="layui-form-label">单据状态</label>
            	<div class="layui-input-inline">
              		<select name="processStatus">
		              	<option value="">请选择-单据状态</option>
		              	<option value="1">审批中</option>
		              	<option value="9">审批完成</option>
		              	<option value="10">审批终止</option>
              		</select>
            	</div>
          	</div>
          	<shiro:hasPermission name="LIST_CONTRACTEXT">
          	<div class="layui-inline">
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-contractExt-search">
	              	<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	            </button>
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              	<i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            </button>
          	</div>
          	</shiro:hasPermission>
        </div>   	
    </div>       
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
      	<div style="padding-bottom: 10px;">
          	<shiro:hasPermission name="ADD_CONTRACTEXT">
          		<button class="layui-btn layuiadmin-btn-admin " data-type="add">
          	 		<i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新建
          		</button>
          	</shiro:hasPermission>
          	<shiro:hasPermission name="EXPORT_CONTRACTEXT">
          		<button class="layui-btn layuiadmin-btn-admin " data-type="export" onclick="exportList();">
          	 		<i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出
          		</button>
          </shiro:hasPermission>
        </div>
        <!-- 数据表单 -->
        <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
        	<ul class="layui-tab-title">
            	<li class="layui-this" lay-id="create"><B>我发起的</B></li>
                <li lay-id="wait"><B>我审批的</B></li>
            </ul>
            <div class="layui-tab-content">
            	<div class="layui-tab-item layui-show">
        			<table id="LAY-contractExt-create-manage" lay-filter="LAY-contractExt-create-manage"></table>
                </div>
                <div class="layui-tab-item">
                    <table id="LAY-contractExt-wait-manage" lay-filter="LAY-contractExt-wait-manage"></table>
                </div>
            </div>
        </div>
        <!-- 补充签订 -->
          <form class="layui-form" lay-filter="supply_form" id="supply_form" style="padding: 20px 30px 0 0;display:none">
            <input type="hidden" name="id"/>
            <div class="layui-form-item">
                <div class="layui-inline">
			    	<label class="layui-form-label">项目名称</label>
			      	<div class="layui-input-inline">
				      	<input type="text" name="proName" style="border:0px;" readonly="readonly" class="layui-input">
			      	</div>
			    </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
			    	<label class="layui-form-label">合同类型</label>
			      	<div class="layui-input-inline">
				      	<input type="text" id="extType" style="border:0px;" readonly="readonly" class="layui-input">
			      	</div>
				</div>
            </div>
           <div class="layui-form-item">
	           <div class="layui-inline">
	             	<label class="layui-form-label">合同签订日</label>
	             	<div class="layui-input-inline">
	               		<input type="text" class="layui-input" id="signDate-laydate" lay-verify="required" name="signDate" readonly placeholder="合同签订日">
	             	</div>
	       		</div>
 			</div>
 			<div style="margin-top:20px">
				<div class="layui-form-item">
	                <label class="layui-form-label">补充附件</label>
	                <div class="layui-input-inline">
	               		<input type="text" value="*支持pdf、excel、word、图片资料，可上传多张" style="border:0px;width:350px" readonly="readonly" class="layui-input">
	             	</div>
	            </div>
	            <div class="layui-form-item">
				    <label class="layui-form-label">Word版合同文本（选填）</label>
				    <div class="layui-input-block">
				    	<div class="layui-upload">
			              	<button type="button" class="layui-btn" id="1-upload-more">新增</button>
	                		<div class="layui-upload-list" id="1-upload-more-list">
	                		</div>
			            </div>
				    </div>
			  	</div>
			    <div class="layui-form-item">
				    <label class="layui-form-label">PDF版合同文本（选填）</label>
				    <div class="layui-input-block">
				    	<div class="layui-upload">
			              	<button type="button" class="layui-btn" id="2-upload-more">新增</button>
	                		<div class="layui-upload-list" id="2-upload-more-list">
	                		</div>
			            </div>
				    </div>
			  	</div>
			    <div class="layui-form-item">
				    <label class="layui-form-label">盖章版合同文本（选填）</label>
				    <div class="layui-input-block">
				    	<div class="layui-upload">
			              	<button type="button" class="layui-btn" id="3-upload-more">新增</button>
	                		<div class="layui-upload-list" id="3-upload-more-list">
	                		</div>
			            </div>
				    </div>
			  	</div>
			    <div class="layui-form-item">
				    <label class="layui-form-label">其他附件（选填）</label>
				    <div class="layui-input-block">
				    	<div class="layui-upload">
			              	<button type="button" class="layui-btn" id="4-upload-more">新增</button>
	                		<div class="layui-upload-list" id="4-upload-more-list">
	                		</div>
			            </div>
				    </div>
			  	</div>
		  	</div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="supply_form_submit" id="supply_form_submit" value="确认">
            </div>
        </form>
        <!-- 选择合同类型 -->
        <div class="layui-form" lay-filter="add_from" id="add_from" style="padding: 20px 30px 0 0;display:none">
		    <div class="layui-form-item">
		      	<label class="layui-form-label">合同类型</label>
		      	<div class="layui-input-block">
			      	<input type="radio" name="types" value="1" title="原合同" checked>
			      	<input type="radio" name="types" value="2" title="补充合同">
		    	</div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="add_from_submit" id="add_from_submit" value="确认">
		    </div>
	  	</div>
      </div>
    </div>
  </div>

  <script>
  	layui.config({
    	base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index' //主入口模块
  	}).use(['index', 'table', 'set', 'upload','transfer', 'laydate'], function(){
    	var $ = layui.$
    	,form = layui.form
    	,table = layui.table
    	,element = layui.element
    	,laydate = layui.laydate
    	,upload = layui.upload;
    	//tab重新渲染宽度
    	element.on('tab(component-tabs-brief)', function(obj){
    		$(window).resize();
    	});
    	
  	    //开始日期
  	    var insStart = laydate.render({
  	      elem: '#sent-laydate-start'
  	      ,done: function(value, date){
  	        //更新结束日期的最小日期
  	        insEnd.config.min = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	        
  	        //自动弹出结束日期的选择器
  	       insEnd.config.elem[0].focus();
  	      }
  	    });
  	    
  	    //结束日期
  	    var insEnd = laydate.render({
  	      elem: '#sent-laydate-end'
  	      ,done: function(value, date){
  	        //更新开始日期的最大日期
  	        insStart.config.max = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	      }
  	    });
  	    
  		//合同签订日
  	    var signDate =laydate.render({
  	    	 elem: '#signDate-laydate'
  	  	     ,type:'date'
  	  	     ,format:'yyyy-MM-dd'
   	  	});
 		// 正则校验
    	form.verify({
    		//验证汉字
    	    CHS: [
    	    	/^[\u0391-\uFFE5]+$/
    	    	,'只能输入汉字'
    	  	],
	    	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	]
		});
    	var supplyState = '';
    	// 表单
    	table.render({
      		elem: '#LAY-contractExt-create-manage'
      		,url: basePath + '/contractExt/queryDataByCondition?hrStaffApplyId=${SESSION_KEY_USER_DETAIL.hrStaffId }' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'codes', title: '单据ID', width: 170,align:'center'}
        		,{field: 'proName', title: '项目名称', width: 280,align:'center'}
        		,{field: 'contractExtName', title: '承继协议名称',width: 210,align:'center'}
        		,{field: 'versionNo', title: '合同版本',width: 100,align:'center'}
        		,{field: 'extType', title: '合同类型',width: 100,align:'center', templet: function(d){
	        			if(d.extType == '1'){
	        				return '原合同';
	        			}else if(d.extType == '2'){
	        		  		return '补充合同';
	          			}
	    			}
	     		}
        		,{field: 'contractExtSaName', title: '补充协议名称',width: 170,align:'center'}
        		,{field: 'proLeader', title: '项目负责人',width: 100,align:'center'}       		
        		,{field: 'beginBulidDate', title: '合同开工日期',width: 130,align:'center', templet: function(d){
        		  	return layui.util.toDateString(d.beginBulidDate,"yyyy-MM-dd");
          			}
         		}
        		,{field: 'totalYears', title: '总合同期（年）',width: 130,align:'center'}
        		,{field: 'totalSum', title: '合同总投资（元）',width: 150,align:'center', templet: function(d){
    				return formatCurrency(d.totalSum);
          		}}      		
        		,{field: 'orgName', title: '申请公司',width: 170,align:'center'}
        		,{field: 'deptName', title: '申请部门',width: 100,align:'center'}
        		,{field: 'staffName', title: '申请人',width: 100,align:'center'}
        		,{field: 'addTime', title: '创建时间', width: 170,align:'center', templet: function(d){
        		  		return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
              		}
             	}
        		,{field: 'processStatus', title: '单据状态', width: 103, fixed: 'right',align:'center', templet: function(d){
	        			if(d.processStatus == '1'){
	    					supplyState = '1';
	    					return '审批中';
	    				}else if(d.processStatus == '9'){
	    					supplyState = '9';
	    					return '审批完成';
	    				}else if(d.processStatus == '10'){
	    					supplyState = '10';
	    					return '<span class="layui-badge layui-bg-cyan">审批终止</span>';
	    				}
              		}
        		}
        		,{title: '操作', width: 230, align:'center', fixed: 'right',align:'center', templet: function(d){
      	  				var optStr ="";
      	  				<shiro:hasPermission name="VIEW_CONTRACTEXT">
      	  					optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>详情</a>';
  	  	  				</shiro:hasPermission>
		  	  	  		<shiro:hasPermission name="SUPPLY_CONTRACTEXT">
				  	  	  	if(supplyState == '9' && d.signDate==null){
		  	  	  				optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="supply"><i class="layui-icon layui-icon-edit"></i>补充签订</a>';
		  	  	  			}else{
		  	  	  				optStr += '';
		  	  	  			}		                	
		                </shiro:hasPermission>
		                if(d.processStatus == '10'){
		                	<shiro:hasPermission name="COPY_CONTRACTEXT">
	  	  	  					optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="copy"><i class="layui-icon layui-icon-release"></i>复制单据</a>';
	  	  					</shiro:hasPermission>
	  	  					optStr += '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
	  	  	  			}
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});
    	
    	// 表单
    	table.render({
      		elem: '#LAY-contractExt-wait-manage'
      		,url: basePath + '/contractExt/queryMyCheckDataByCondition' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'codes', title: '单据ID', width: 170,align:'center'}
        		,{field: 'proName', title: '项目名称', width: 280,align:'center'}
        		,{field: 'contractExtName', title: '承继协议名称',width: 210,align:'center'}
        		,{field: 'versionNo', title: '合同版本',width: 100,align:'center'}
        		,{field: 'extType', title: '合同类型',width: 100,align:'center', templet: function(d){
	        			if(d.extType == '1'){
	        				return '原合同';
	        			}else if(d.extType == '2'){
	        		  		return '补充合同';
	          			}
	    			}
	     		}
        		,{field: 'contractExtSaName', title: '补充协议名称',width: 170,align:'center'}
        		,{field: 'proLeader', title: '项目负责人',width: 100,align:'center'}       		
        		,{field: 'beginBulidDate', title: '合同开工日期',width: 130,align:'center', templet: function(d){
        		  		return layui.util.toDateString(d.beginBulidDate,"yyyy-MM-dd");
          			}
         		}
        		,{field: 'totalYears', title: '总合同期（年）',width: 130,align:'center'}
        		,{field: 'totalSum', title: '合同总投资（元）',width: 150,align:'center', templet: function(d){
    				return formatCurrency(d.totalSum);
          		}} 
        		,{field: 'orgName', title: '申请公司',width: 170,align:'center'}
        		,{field: 'deptName', title: '申请部门',width: 100,align:'center'}
        		,{field: 'staffName', title: '申请人',width: 100,align:'center'}
        		,{field: 'addTime', title: '创建时间', width: 170,align:'center', templet: function(d){
        		  		return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
              		}
             	}
        		,{field: 'mineStatus', width: 105,title: '审批状态',fixed: 'right',align:'center',templet: function(d){
	              	  var stateStr = '';
	          		  if(d.mineStatus == '0'){
	          			  stateStr = '我已审批';
	          		  }else if(d.mineStatus == '1'){
	          			  stateStr = '<span class="layui-badge layui-bg-red">待我审批</span>';
	          		  }else if(d.mineStatus == '9'){
	          			  stateStr = '审批完成';
	          		  }else if(d.mineStatus == '10'){
	          			  stateStr = '<span class="layui-badge layui-bg-cyan">审批终止</span>';
	          		  }
	        			  return stateStr;
	               }
	        	}
        		,{title: '操作', width: 171, align:'center', fixed: 'right', templet: function(d){
      	  				var optStr ="";
      	  				<shiro:hasPermission name="VIEW_CONTRACTEXT">
      	  					optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>详情</a>';
  	  	  				</shiro:hasPermission>
	  	  	  			<shiro:hasPermission name="CHECK_CONTRACTEXT">
		  	  				if(d.mineStatus == '1'){
			  	  				optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="toDispatch"><i class="layui-icon layui-icon-release"></i>去审批</a>';
		  	  				}
	  	  				</shiro:hasPermission>
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});
    
    	<shiro:hasPermission name="LIST_CONTRACTEXT">
	    	//监听搜索
	    	form.on('submit(LAY-contractExt-search)', function(data){
	    		var tabId = $(".layui-tab-title .layui-this").attr("lay-id");
	    		if(tabId == 'create'){
	    			//执行重载
			      	table.reload('LAY-contractExt-create-manage', {page: {curr: 1},
			        	where: trimData(data)
			      	});
	    		}else{
	    			//执行重载
			      	table.reload('LAY-contractExt-wait-manage', {page: {curr: 1},
			        	where: trimData(data)
			      	});
	    		}
	    	});
	    	//重置清空
		    form.on('submit(LAY-user-back-reset)', function(data){
		    	reset_form('query-form');
		    	//额外处理select
				$("#query-form-state").val('');
				form.render();
		    });
    	</shiro:hasPermission>
    
    	// 监听操作列
    	table.on('tool(LAY-contractExt-create-manage)', function(obj){
      		var data = obj.data;
 			if(obj.event === 'view'){
	       		parent.layui.index.openTabsPage(basePath + '/contractExt/toDealOrDetail?id='+data.id,'承继协议 > 详情');
	   		}else if(obj.event === 'supply'){
	   			$("#1-upload-more-list").html('');//清空上传文件
	    	  	$("#2-upload-more-list").html('');//清空上传文件
	    	  	$("#3-upload-more-list").html('');//清空上传文件
	    	  	$("#4-upload-more-list").html('');//清空上传文件
	    	  	$("input[name=id]").val(data.id)// 填充原值
	    	  	$("input[name=proName]").val(data.proName)// 填充原值
   				$("#extType").val(data.extType == '1' ? '承继协议':'承继协议补充合同');
	               layer.open({
	                   type: 1
	                   ,title: '补充签订'
	                   ,content: $('#supply_form')
	                   ,area: layui.admin.screen() <  2 ? ['80%', '720px'] : ['750px','550px']
	                   ,btn: ['确定', '取消']
	                   ,btnAlign: 'c'
	                   ,yes: function(index, layero){
		                	 //判断是否上传了Word版合同文本
		               		if ($("input[name=signDate]").val() == '') {
		               			layer.msg("合同签订日不能为空", {
		               				icon : 0
		               			});
		               			return;
		               		}
	                       var submitID = 'supply_form_submit'
	                           ,submit = layero.contents().find('#'+ submitID);
	                       //监听提交
	                       form.on('submit('+ submitID +')', function(data){
	                    	   
	                           //var field = data.field; //获取提交的字段
	                           var field =$('#supply_form').serialize();
	                           //提交 Ajax 成功后，静态更新表格中的数据
	                           $.ajax({
	                               type : 'post',
	                               url : basePath + '/contractExt/sign',
	                               data: field,
	                               success:function(result){
	                                   if(result.success){
	                                       table.reload('LAY-contractExt-create-manage'); //数据刷新
	                                       layer.close(index); //关闭弹层
	                                       clean_form('supply_form');//清空表单
	                                   }else{
	                                       layer.msg(result.msg,{icon: 7});
	                                   }
	                               }
	                          
	                           });
	                       });
	                       submit.trigger('click');
	                   }
	               });
		   		//Word版合同文本
	   		  	upload.render({
	   			      elem: '#1-upload-more'
	   			      ,url: basePath + '/contractExt/uploadAtt/'
	   			      ,data: {
	   			    	  types:1
	   			    		}
	   			      ,multiple: true
	   			      ,accept: 'file'
	   			      ,acceptMime: 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document'
	   			   	  ,before: function(obj){ //obj参数包含的信息
	   			   		    layer.load(); //上传loading
	   			   		  }
	   			      ,done: function(res){
	   			    	  //如果上传失败
	   			          if(res.code > 0){
	   			        	  layer.closeAll('loading'); //关闭loading
	   			        	  return layer.msg(res.msg,{icon: 7});
	   			          }
	   			          //上传完毕
	   			   	  	  if(res.entity != null && res.entity.length > 0){
	   						for(var i in res.entity){
	   							var contractExt = res.entity[i];
	   							var arr = contractExt.split("|");
	   							var imgSrc = "";
	   							var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
	   							if(suffix == 'jpg' || suffix == 'png'){
	   								imgSrc = "${fileHttpPre}/"+arr[3];
	   							}else{
	   								imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
	   							}
	   			        		$('#1-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+contractExt+'" id="fileAtt_'+arr[2]+'" name="fileAtt1" ></input></div> ');
	   						}
	   				  	  }
	   			      }
	   			      ,allDone: function(obj){ //当文件全部被提交后，才触发
	   			    	  layer.closeAll('loading'); //关闭loading
	   			      }
	   			      ,error: function(){
	   			    	  layer.closeAll('loading'); //关闭loading
	   			          //上传失败
	   			          layer.msg("上传失败，请稍后再试~",{icon: 7});
	   			        }
	   			    });
	   			
	   			//PDF版合同文本
	   		  	upload.render({
	   			      elem: '#2-upload-more'
	   			      ,url: basePath + '/contractExt/uploadAtt/'
	   			      ,data: {
	   			    	  types:2
	   			    		}
	   			      ,multiple: true
	   			      ,accept: 'file'
	   			      ,acceptMime: 'application/pdf'
	   			   	  ,before: function(obj){ //obj参数包含的信息
	   			   		    layer.load(); //上传loading
	   			   		  }
	   			      ,done: function(res){
	   			    	  //如果上传失败
	   			          if(res.code > 0){
	   			        	  layer.closeAll('loading'); //关闭loading
	   			        	  return layer.msg(res.msg,{icon: 7});
	   			          }
	   			          //上传完毕
	   			   	  	  if(res.entity != null && res.entity.length > 0){
	   						for(var i in res.entity){
	   							var fileAtt = res.entity[i];
	   							var arr = fileAtt.split("|");
	   							var imgSrc = "";
	   							var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
	   							if(suffix == 'jpg' || suffix == 'png'){
	   								imgSrc = "${fileHttpPre}/"+arr[3];
	   							}else{
	   								imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
	   							}
	   			        		$('#2-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+fileAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt2" ></input></div> ');
	   						}
	   				  	  }
	   			      }
	   			      ,allDone: function(obj){ //当文件全部被提交后，才触发
	   			    	  layer.closeAll('loading'); //关闭loading
	   			      }
	   			      ,error: function(){
	   			    	  layer.closeAll('loading'); //关闭loading
	   			          //上传失败
	   			          layer.msg("上传失败，请稍后再试~",{icon: 7});
	   			        }
	   			    });
	   			
	   			//盖章版合同文本（选填）
	   			upload.render({
	   			      elem: '#3-upload-more'
	   			      ,url: basePath + '/contractExt/uploadAtt/'
	   			      ,data: {
	   			    	  types:3
	   			    		}
	   			      ,multiple: true
	   			      ,accept: 'file'
	   			      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   			   	  ,before: function(obj){ //obj参数包含的信息
	   			   		    layer.load(); //上传loading
	   			   		  }
	   			      ,done: function(res){
	   			    	  //如果上传失败
	   			          if(res.code > 0){
	   			        	  layer.closeAll('loading'); //关闭loading
	   			        	  return layer.msg(res.msg,{icon: 7});
	   			          }
	   			          //上传完毕
	   			   	  	  if(res.entity != null && res.entity.length > 0){
	   						for(var i in res.entity){
	   							var fileAtt = res.entity[i];
	   							var arr = fileAtt.split("|");
	   							var imgSrc = "";
	   							var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
	   							if(suffix == 'jpg' || suffix == 'png'){
	   								imgSrc = "${fileHttpPre}/"+arr[3];
	   							}else{
	   								imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
	   							}
	   			        		$('#3-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+fileAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt3" ></input></div> ');
	   						}
	   				  	  }
	   			      }
	   			      ,allDone: function(obj){ //当文件全部被提交后，才触发
	   			    	  layer.closeAll('loading'); //关闭loading
	   			      }
	   			      ,error: function(){
	   			    	  layer.closeAll('loading'); //关闭loading
	   			          //上传失败
	   			          layer.msg("上传失败，请稍后再试~",{icon: 7});
	   			        }
	   			    });
	   			
	   			//其他附件（选填）
	   		  	upload.render({
	   			      elem: '#4-upload-more'
	   			      ,url: basePath + '/contractExt/uploadAtt/'
	   			      ,data: {
	   			    	  types:4
	   			    		}
	   			      ,multiple: true
	   			      ,accept: 'file'
	   			      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   			   	  ,before: function(obj){ //obj参数包含的信息
	   			   		    layer.load(); //上传loading
	   			   		  }
	   			      ,done: function(res){
	   			    	  //如果上传失败
	   			          if(res.code > 0){
	   			        	  layer.closeAll('loading'); //关闭loading
	   			        	  return layer.msg(res.msg,{icon: 7});
	   			          }
	   			          //上传完毕
	   			   	  	  if(res.entity != null && res.entity.length > 0){
	   						for(var i in res.entity){
	   							var fileAtt = res.entity[i];
	   							var arr = fileAtt.split("|");
	   							var imgSrc = "";
	   							var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
	   							if(suffix == 'jpg' || suffix == 'png'){
	   								imgSrc = "${fileHttpPre}/"+arr[3];
	   							}else{
	   								imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
	   							}
	   			        		$('#4-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'+fileAtt+'" id="fileAtt_'+arr[2]+'" name="fileAtt4" ></input></div> ');
	   						}
	   				  	  }
	   			      }
	   			      ,allDone: function(obj){ //当文件全部被提交后，才触发
	   			    	  layer.closeAll('loading'); //关闭loading
	   			      }
	   			      ,error: function(){
	   			    	  layer.closeAll('loading'); //关闭loading
	   			          //上传失败
	   			          layer.msg("上传失败，请稍后再试~",{icon: 7});
	   			        }
	   			    });
		   		}else if(obj.event === 'del'){//删除
	      			layer.confirm('确定要删除？',{icon:3, title :'提示'}, function(index){
	          			$.ajax({
	            			type : 'post',
	    						url : basePath + '/flowProcess/logicDel',
	    						data : {
	    		    				"processId" :data.processId
	    		    			},//数据，这里使用的是Json格式进行传输  
	    						success:function(result){
	    							if(result){
	        							table.reload('LAY-contractExt-create-manage'); //数据刷新
	        							layer.close(index); //关闭弹层
	    							}else{
	    								layer.msg('数据通信异常~',{icon: 0});
	    			  				}
	    						}
	        			});
	       			})
	       		}else if(obj.event === 'copy'){//复制单据
	       			if(data.extType == '1'){
	       				parent.layui.index.openTabsPage(basePath + '/contractExt/toCopy?id='+data.id+'&extType='+data.extType,'承继协议原合同 > 复制单据');
	       			}else if(data.extType == '2'){
	       				parent.layui.index.openTabsPage(basePath + '/contractExt/toCopy?id='+data.id+'&extType='+data.extType,'承继协议补充协议 > 复制单据');
	       			}
		   		}
	    	});
    	
    	// 监听操作列
    	table.on('tool(LAY-contractExt-wait-manage)', function(obj){
	      		var data = obj.data;
	 			if(obj.event === 'view'){
	       			parent.layui.index.openTabsPage(basePath + '/contractExt/toDealOrDetail?id='+data.id,'承继协议 > 详情');
	   			}else if(obj.event === 'toDispatch'){
	   	    	  	parent.layui.index.openTabsPage(basePath + '/flowProcess/toDispatch?processId='+data.processId, '承继协议 '+ ' > 审批');
	   	      	}
    	});
    
    // 按钮事件
    var active = {
      add: function(){
    	  layer.open({
        	  type: 1
        	  ,title: '新增承继协议'
        	  ,content: $('#add_from')
        	  ,area: layui.admin.screen() < 2 ? ['80%', '180px'] : ['420px','180px']
        	  ,btn: ['去新增', '取消']
        	  ,btnAlign: 'c'
        	  ,yes: function(index, layero){
        		  	var types = $('[name="types"]:checked').val();
        		  	if(types=='1'){
        	        	  parent.layui.index.openTabsPage(basePath + '/contractExt/add?types='+types,'承继协议原合同 > 新建');
        	          }else if(types=='2'){
        	        	  parent.layui.index.openTabsPage(basePath + '/contractExt/add?types='+types,'承继协议补充协议 > 新建');
        	          } 
        		  	layer.close(index); //关闭弹窗
          		}
        }); 

      }
    }  
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    
  });
	
	//删除文件
	function del(index){
		layui.$("#fileAtt_"+index).remove();
		layui.$("#upload_img_"+index).remove();
	}

	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
  	//导出excel
   	function exportList() {
   		layer.msg("暂未上线，敬请期待~",{icon: 1});
		/*var $ = layui.$;
		var params = "?proCode=";
		params += $('#queryProCode').val().trim();
    	params += "&startDate=";
    	params += $('#sent-laydate-start').val().trim();
    	params += "&endDate=";
    	params += $('#sent-laydate-end').val().trim();
		params += "&customerName=";
    	params += $('#queryCustomerName').val().trim();
		params += "&mobile=";
    	params += $('#queryMobile').val().trim();
		params += "&provinceName=";
    	params += $('#queryProvinceName').val().trim();
		params += "&cityName=";
    	params += $('#queryCityName').val().trim();
		params += "&state=";
    	params += $('#queryState').val().trim();
		window.location.href = "${ctx}/preProject/exportToExcel"+params;*/
	}
  </script>
</body>
</html>

